package controller.servlet.paymentForms;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Card;
import model.Company;
import controller.dao.Dao_Card;
import controller.dao.Dao_Company;

public class Register extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Dao_Company daoC = new Dao_Company();
	    Company company = daoC.list(1);
	    if(company == null){
	    	company = new Company();
	    	company.setCnpj("1234567890");
	    	company.setCorporateName("ShoppingCart.Com, Inc.");
	    }
	    getServletContext().setAttribute("company", company);
	    String flag = request.getParameter("flag");
	    Company company2 = (Company)getServletContext().getAttribute("company");
	    Card card = new Card();
	    card.setFlag(flag);
	    card.setCompany(company2);
	    Dao_Card daoCar = new Dao_Card();
	    daoCar.save(card);
	    response.getWriter().print("1");
	}
}
